package com.ex.kafka.service;

import com.alibaba.fastjson.JSONArray;
import com.ex.kafka.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author longdeng
 * @Date 2020/3/29 0029 9:45
 */
@Service
public class KafkaService {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    public void sendMsg() {

        for (int i = 0; i < 100; i++) {
            final String userStr = JSONArray.toJSONString(new User(i + 1, "zhouxl" + 1, "zhoouxl" + 1));
            kafkaTemplate.send("demo", userStr);
        }

    }
}
